using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using RecruitmentSystem.Business;
using RecruitmentSystem.Common;
using System.Collections.Generic;

public partial class SystemManagement_GetSecondCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["cid"] != "level1")
            {
                int categoryid = Convert.ToInt32(Request.QueryString["cid"]);
                Response.Write(GetCategoryByParentId(categoryid));
            }
        }
    }

    private string GetCategoryByParentId(int pid)
    {
        string resultStr = "";
        if (pid != 0)
        {
            List<Category> categoryList = Application["AllCategory"] as List<Category>;
            if (categoryList == null || categoryList.Count <= 0)
            {
                NewsManager nm = new NewsManager();
                categoryList = nm.GetAllCategory(null);
                Application["AllCategory"] = categoryList;
            }
            foreach (Category ctg in categoryList)
            {
                if (ctg.ParentId == pid)
                {
                    if (resultStr == "")
                    {
                        resultStr = ctg.Name + "|" + ctg.Id.ToString();
                    }
                    else
                    {
                        resultStr += "," + ctg.Name + "|" + ctg.Id.ToString();
                    }
                }
            }
        }
        return resultStr;
    }
}
